home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / include / libpurple / circbuffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-04  |  3.8 KB  |  118 lines

  1. /*
  2.  * @file circbuffer.h Buffer Utility Functions
  3.  * @ingroup core
  4.  *
  5.  * Purple is the legal property of its developers, whose names are too numerous
  6.  * to list here.  Please refer to the COPYRIGHT file distributed with this
  7.  * source distribution.
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22.  */
  23. #ifndef _CIRCBUFFER_H
  24. #define _CIRCBUFFER_H
  25.  
  26. #include <glib.h>
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. typedef struct _PurpleCircBuffer {
  33.  
  34.     /** A pointer to the starting address of our chunk of memory. */
  35.     gchar *buffer;
  36.  
  37.     /** The incremental amount to increase this buffer by when
  38.      *  the buffer is not big enough to hold incoming data, in bytes. */
  39.     gsize growsize;
  40.  
  41.     /** The length of this buffer, in bytes. */
  42.     gsize buflen;
  43.  
  44.     /** The number of bytes of this buffer that contain unread data. */
  45.     gsize bufused;
  46.  
  47.     /** A pointer to the next byte where new incoming data is
  48.      *  buffered to. */
  49.     gchar *inptr;
  50.  
  51.     /** A pointer to the next byte of buffered data that should be
  52.      *  read by the consumer. */
  53.     gchar *outptr;
  54.  
  55. } PurpleCircBuffer;
  56.  
  57. /**
  58.  * Creates a new circular buffer.  This will not allocate any memory for the
  59.  * actual buffer until data is appended to it.
  60.  *
  61.  * @param growsize The amount that the buffer should grow the first time data
  62.  *                 is appended and every time more space is needed.  Pass in
  63.  *                 "0" to use the default of 256 bytes.
  64.  *
  65.  * @return The new PurpleCircBuffer. This should be freed with
  66.  *         purple_circ_buffer_destroy when you are done with it
  67.  */
  68. PurpleCircBuffer *purple_circ_buffer_new(gsize growsize);
  69.  
  70. /**
  71.  * Dispose of the PurpleCircBuffer and free any memory used by it (including any
  72.  * memory used by the internal buffer).
  73.  *
  74.  * @param buf The PurpleCircBuffer to free
  75.  */
  76. void purple_circ_buffer_destroy(PurpleCircBuffer *buf);
  77.  
  78. /**
  79.  * Append data to the PurpleCircBuffer.  This will grow the internal
  80.  * buffer to fit the added data, if needed.
  81.  *
  82.  * @param buf The PurpleCircBuffer to which to append the data
  83.  * @param src pointer to the data to copy into the buffer
  84.  * @param len number of bytes to copy into the buffer
  85.  */
  86. void purple_circ_buffer_append(PurpleCircBuffer *buf, gconstpointer src, gsize len);
  87.  
  88. /**
  89.  * Determine the maximum number of contiguous bytes that can be read from the
  90.  * PurpleCircBuffer.
  91.  * Note: This may not be the total number of bytes that are buffered - a
  92.  * subsequent call after calling purple_circ_buffer_mark_read() may indicate more
  93.  * data is available to read.
  94.  *
  95.  * @param buf the PurpleCircBuffer for which to determine the maximum contiguous
  96.  *            bytes that can be read.
  97.  *
  98.  * @return the number of bytes that can be read from the PurpleCircBuffer
  99.  */
  100. gsize purple_circ_buffer_get_max_read(const PurpleCircBuffer *buf);
  101.  
  102. /**
  103.  * Mark the number of bytes that have been read from the buffer.
  104.  *
  105.  * @param buf The PurpleCircBuffer to mark bytes read from
  106.  * @param len The number of bytes to mark as read
  107.  *
  108.  * @return TRUE if we successfully marked the bytes as having been read, FALSE
  109.  *         otherwise.
  110.  */
  111. gboolean purple_circ_buffer_mark_read(PurpleCircBuffer *buf, gsize len);
  112.  
  113. #ifdef __cplusplus
  114. }
  115. #endif
  116.  
  117. #endif /* _CIRCBUFFER_H */
  118.